package ComparatorAndComparable.TreeSetDemo_Comparable;

public class Student implements Comparable<Student> {
    private String name;
    private Integer age;

    public Student(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public Student() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Student s) {
        // 0: 相等
        // 1: 认为下一个比第一个大,升序
        // -1: 认为下一个比第一个小,倒着显示，还是他以为的升序
//        return -1;

        // this是s2
        int num = this.age - s.age;
//        int num = s.age - this.age;

        int num2 = num == 0 ? this.name.compareTo(s.name) : num;
        return num2;
    }
}
